package com.cpe.transfer.student;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.cpe.data.domain.student.classproject.StudentClassProject;
import com.cpe.data.domain.student.classproject.StudentClassProjectForm;
import com.cpe.data.domain.student.classproject.StudentClassProjectInfo;
import com.cpe.repository.mapper.student.StudentClassProjectMapper;
import com.google.common.collect.Lists;

@Component
public class StudentClassProjectTransfer {

	@Resource
	private StudentClassProjectMapper studentClassProjectMapper;

	/**
	 * 表单-->实体
	 */
	public StudentClassProject toEntity(StudentClassProjectForm form) {
		Assert.notNull(form);
		StudentClassProject studentClassProject = new StudentClassProject();
		BeanUtils.copyProperties(form, studentClassProject);
		studentClassProject.setScoreDate(new Date());
		studentClassProject.setUpdateTime(new Date());
		return studentClassProject;
	}

	/**
	 * 实体-->响应
	 */
	public StudentClassProjectInfo toInfo(StudentClassProject studentClassProject) {
		Assert.notNull(studentClassProject);
		StudentClassProjectInfo info = new StudentClassProjectInfo();
		BeanUtils.copyProperties(studentClassProject, info);
		info.scoreDesc(studentClassProject.getLtScorePercent());
		return info;
	}

	/**
	 * 实体集-->响应集
	 */
	public List<StudentClassProjectInfo> toInfoList(List<StudentClassProject> list) {
		Assert.notNull(list);
		List<StudentClassProjectInfo> infoList = Lists.newArrayList();
		list.forEach(studentClassProject -> {
			infoList.add(toInfo(studentClassProject));
		});
		return infoList;
	}

	/**
	 * 实体集-->响应集
	 */
	public List<List<StudentClassProjectInfo>> toInfoListGroup(List<List<StudentClassProject>> listGroup) {
		Assert.notNull(listGroup);
		List<List<StudentClassProjectInfo>> infoListGroup = Lists.newArrayList();
		listGroup.forEach(list -> {
			infoListGroup.add(toInfoList(list));
		});
		return infoListGroup;
	}
}
